package com.fashion.service;

import com.fashion.exceptions.NewsNotFoundException;
import com.fashion.model.Administrator;
import com.fashion.model.News;
import com.fashion.model.NewsColumn;
import com.fashion.model.NewsColumnItem;
import com.fashion.utils.NewsTemplate;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: juventus
 * Date: 11-5-30
 * Time:
 */
public interface NewsService extends BaseService {
    String OldPageSplitter = "<div style=\"page-break-after: always;\"><span style=\"display: none;\">&nbsp;</span></div>";
    String OldPageSplitterReg = "(?i)<div style=\"page-break-after:\\s?always;?\\s?\"><span style=\"display:\\s?none;?\">\\s*&nbsp;?\\s*</span></div>";
    String PageSplitter = "<hr style=\"page-break-after:always;\" class=\"ke-pagebreak\" />";
    String PageSplitterReg = "(?i)<hr style=\"page-break-after:\\s*always;?\\s*\" class=\"ke-pagebreak\\s*\"\\s*/>";

    News getNewsById(String id) throws NewsNotFoundException;

    List<News> searchNews(Administrator author, String title, String indexTitle, String newsColumnId, int inIndex, int indexLevel, int pageNumber, int pageSize);

    void handleColumnsForNews(News news, List<String> columnIds);

    int countNews(Administrator author, String title, String indexTitle, String newsColumnId, int inIndex, int indexLevel);

    List<News> searchAboutNews(String newsId, int pageNumber, int pageSize);

    int countAboutNews(String id);

    int countNonAboutNews(String id, String newsTitle, String newsColumnId);

    List<News> searchNonAboutNews(String newsId, String newsTitle, String newsColumnId, int pageNumber, int pageSize);

    void addAboutNews(String sourceNewsId, String targetNewsId);

    void deleteAboutNews(String sourceNewsId, String targetNewsId);

    List<News> searchSuggestNews(String newsTitle, String newsColumnId, int page, int rows);

    int countSuggestNews(String newsTitle, String newsColumnId);

    List<News> searchNonSuggestNews(String newsTitle, String newsColumnId, int page, int rows);

    int countNonSuggestNews(String newsTitle, String newsColumnId);

    void addSuggestNews(String targetNewsId);

    void deleteSuggestNews(String[] newsIds);

    void saveThumbNail(File file, String saveName, String folder) throws IOException;

    boolean checkVerticalImage(File file) throws IOException;

    List<News> searchTagNews(String keyword, int page, int rows);

    List<News> searchTagNews(List<String> keywords, int page, int rows);

    int countTagNews(String keyword);

    List<News> searchNewsByColumn(String newsColumnName, int pageNumber, int pageSize);

    int countNewsByColumn(String columnName);

    List<News> searchNewsByColumnId(String columnId, int pageNumber, int pageSize);

    List<News> searchNewsByColumns(List<NewsColumn> columns, int pageNumber, int pageSize);

    int countNewsByColumnId(String columnId);

    public int countNewsByColumns(List<NewsColumn> columns);

    List<News> searchTopTenNews(String newsColumnName, int pageNumber, int pageSize);

    /**
     * Search news for index page and column index page.
     *
     * @param newsColumnName column name
     * @param newsTemplates  templates contains index level and news count
     * @param inIndex        the minimum inIndex level(Index page:2, column index page:1, ordinary:0)
     * @return list of news information
     */
    List<News> searchNewsByColumnAndTemplateList(String newsColumnName, List<NewsTemplate> newsTemplates, int inIndex);

    List<News> searchNewsByTemplateList(List<NewsTemplate> newsTemplates, int inIndex);

    List<NewsColumnItem> findColumnItemsByNewsId(String id);

    void bulkDeleteNewsColumnItems(List<String> itemIds);

    public List<News> searchNewsByColumnListAndTemplateList(List<NewsColumn> columns, List<NewsTemplate> newsTemplates, int inIndex);

    List<News> searchMostViewedNewsByColumn(String newsColumnId, int pageNumber, int pageSize);

    List<News> searchMostViewedNews(int pageNumber, int pageSize);

    void formatNewsTitle(List<News> newsList, int maxTitleLength);

    List<News> searchAboutNewsByKeywordsList(List<String> rawKeywords, String id);

    List<News> searchDraftNews(String newsTitle, String newsIndexTitle, String newsColumn, int inIndex, int indexLevel, int page, int pageSize);

    int countDraftNews(String newsTitle, String newsIndexTitle, String newsColumn, int inIndex, int indexLevel);

    void saveHtmlNews(String url, String urlPrefix, String basePersistenceFolder) throws Exception;

    void deleteHtmlNews(String id, String basePersistenceFolder);

    List<News> findAllNews();

    List<News> searchNewsByMonths(List<String> months);
}
